import org.w3c.dom.Node;

public class BinaryTree {
    static class TreeNode {
        //孩子法,没有定义双亲
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val){
            this.val = val;
        }
    }

    public TreeNode CreatTree(){
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');

        A.left = B;
        A.right=C;

        B.left=D;
        B.right=E;

        C.left=F;
        C.right=G;

        E.right=H;

        return A;
    }

    //前序遍历
    public void preOrder(TreeNode root){
        if(root==null){
            return;//空树是不需要被遍历的
        }
        System.out.print(root.val+" ");//根
        //利用递归分别遍历左右子树
        preOrder(root.left);
        preOrder(root.right);
    }

    //中序遍历
    public void inOrder(TreeNode root){
        if(root==null){
            return;//空树是不需要被遍历的
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }

    //后序遍历
    public void postOrder(TreeNode root){
        if(root==null){
            return;//空树是不需要被遍历的
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val+" ");
    }
}
